import { param } from "@/utils";
import request from "@/utils/request";

// 查询订单列表
export function listOrder(query, url) {
  return request({
    method: "get",
    params: query,
    url: url,
  });
}

// 查询订单列表 tab 栏
export function listByTab(query) {
  return request({
    url: "/order/order/listByTab",
    method: "post",
    data: query,
  });
}

export function assignOrder(param, component) {
  return request({
    url: "/order/order/assignOrder",
    method: "put",
    data: {
      ...param,
      returnTime: param.returnTime / 1000,
    },
  }).then((res) => {
    if (component) {
      component.$message.success(res.msg);
      component.$emit("receiveData", param);
      component.$emit("close", false);
    }
  }).finally(()=>{
    if(component){
      component.submitLoading = true;
    }
  });
}

/**
 * 根据 userid 获取 关联数据
 * @param {{}} query
 * @returns
 */
export function listOrderByUserId(query) {
  return request({
    url: "/order/order/listByUser",
    method: "get",
    params: query,
  });
}

/**
 * 根据 userid 获取余额支付的 关联数据
 * @param {{}} query
 * @returns
 */
export function listRechargeByUser(query) {
  return request({
    url: "/order/order/listRechargeByUser",
    method: "get",
    params: query,
  });
}

// 查询订单详细
export function getOrder(id) {
  return request({
    url: "/order/order/" + id,
    method: "get",
  });
}

// 新增订单
export function addOrder(data) {
  return request({
    url: "/order/order",
    method: "post",
    data: data,
  });
}

// 修改订单
export function updateOrder(data) {
  return request({
    url: "/order/order",
    method: "put",
    data: data,
  });
}

// 报账合同
export function updateContractOrder(data) {
  return request({
    url: "/order/order/updateContract",
    method: "put",
    data: data,
  });
}

// 翻译证明
export function updateTranslationProofOrder(data) {
  return request({
    url: "/order/order/updateTranslationProofContract",
    method: "put",
    data: data,
  });
}

/**
 * @param {{}} data
 * @returns
 */
export function quotation(data, url = "/order/order/quotation") {
  return request.put(url, data);
}

/**
 * 备注
 * @param {{}} data
 * @returns
 */
export function ktRemark(data) {
  return request.put("/order/order/ktRemark", data);
}

// 删除订单
export function delOrder(id) {
  return request({
    url: "/order/order/" + id,
    method: "delete",
  });
}

//取消订单
export function cancelOrder(id) {
  return request({
    url: "/order/order/cancelOrder",
    method: "post",
    data: {
      id: id,
    },
  });
}

//完工确认
export function confirmOrder(id) {
  return request({
    url: "/order/order/completionConfirmation",
    method: "post",
    data: {
      id: id,
    },
  });
}

//驳回
export function rejectOrder({ id, reason }) {
  return request({
    url: "/order/order/reject",
    method: "post",
    data: {
      id: parseInt(id),
      reason,
    },
  });
}

//编辑人员信息
export function editPersonnel(id) {
  return request({
    url: "/order/order/getEditInfo",
    method: "put",
    data: {
      id: id,
    },
  });
}
// 当前订单处理人列表
export function getOrderHandlerList(params) {
  return request({
    url: "/order/assign/list",
    method: "post",
    data: params,
  });
}

//审核
export function auditOrder(params) {
  return request({
    url: "/order/order/toExamine",
    method: "put",
    data: params
  });
}
